ThtmlReport
  Html Report Component, Version 1.0

Properties     Events     Methods

About   Print Cycle   Report Structure    "Execute" method Source   HTML Viewer

  Why HTML?

•	because HTML is a widespread format

•	it's easy to send HTML Report by E-mail, and view it with a HTML browser

•	it's easy to make transformation into the text format file and print a draft report

•	it's convenient to store fields description in the HTML format file

•	it's possible to generate a several levels report and view it with a built-in HTML browser

•	it's possible to view source data from htmlReport with only one mouse button click

•	it's possible to use tools, which are already created

The htmlReport  component provides an easy way to generate HyperText Markup Language (HTML) reports in a Borland Delphi program.  Creating this component it was wanted to make such a tool for generating reports, which help to print data from an abstract source, i.e. with virtual method  next  you'll be able to pass from one detail line of data to another at the moment of printing. This method has the only one specified characteristic: when the printed data is over next has to give back the value "False", otherwise - "True".

Only the programmers themselves know what they are doing with the method next, so htmlReport component has to demand data with the method GetDetailLine. That is the main feature of the component, which prints reports - at the moment of printing the programmer is able to stay in control:   he can move what he wants with method next, he can give what he wants with method GetDetailLine. All this you are able to change on the spot in connection with data, format, language, etc.

The other feature of this component is the possibility to change some of the report properties, i.e. it is possible to delete report fields, change their positions etc. without recompiling the main program.

It is very easy to create a htmlReport with several levels, because the report is printed as a HTML type file. First of all is displayed sum data which is at the highest level. If the user wants some more detailed data, he must only click the mouse button and  get information. There are 11 of such levels to travel and the price of crossing these levels for the programmer  is only two commands: LoadPrior and Find.

So the htmlReport component helps you concentrate your skills on the logic of your application  instead of writing code for report generating. The HtmlReport component for  DELPHI  provides everything you need to generate professional, HTML-quality reports in you application. The professional version contains a complete component editor, an example code and complete documentation for both 16-bit and 32-bit programming.

The shareware version of the ThtmlViewer may be used without a charge  for personal use.

To order the Professional version, contact:

Valdimaras Jonusas

Internet: proga@klaipeda.omnitel.net


ThtmlViewer

The ThtmlViewer component included in the htmlReport component provides an easy way to display HyperText Markup Language (HTML) documents in a Borland Delphi program.  Version 4.0 of the viewer supports most of the HTML 2.0 specs and several of the more popular HTML 3 enhancements:

•	Images (Bitmap, GIF, PNG, and JPEG)

•	Transparent images

•	Image caching

•	Left and Right floating images

•	IsMap support for images used as anchors

•	Client side image maps (UseMap)

•	Image sizing through Height and Width attributes

•	Large HTML files

•	HTML Tables

•	HTML Forms

•	Font sizes, styles, and colors with HTML tags or default settings

•	Background colors and images

•	Formatted printing of the HTML document

•	Text search

•	Copy to clipboard

•	Subscripts and Superscripts

While HTML documents are normally associated with the Internet World Wide Web, they are also very useful for displaying all kinds of textual material such as documentation, help files, etc.  Graphics are also easily incorporated in these documents.

Updates

For the most recent version of ThtmlViewer and for information on what's coming, check in occasionally at:

David Baldwin

22 Fox Den Road,

Hollis, NH 03049

USA

(603) 465-7857

Internet: dbaldwin@pbear.com

CompuServe:  76327,53

For information on the latest versions of the ThtmlViewer and other Delphi components, drop in occassionally at:

http://www.pbear.com/


ThtmlReport component

About

The  htmlReport component is designed so, that the DELPHI developer wouldn't need to write any code for printing processes. In the main "Execute" method of this printing object a standard printing cycle  which uses OnGetDetailLine, OnGetGroupIndex  and other methods run. They help regulate the course of the printing process. The developer has only to present data, its index and to react to changes of group's index (summing, cleaning sums at lower level, etc.).

The appearance of the report with HTML possibilities is formatted with the component's editor or with any other HTML editor and is saved in the template file, so the developer can concentrate his minds only on how to get data and how to calculate sum fields on htmlReport requests. This you can get compromises:   there is no need to write any codes for the printing process, but you'll be able to keep full control of this process. For this are need to know only the essence of the process, i.e. the instance the event can occur and the sequence of these events. For a simple report it's enough  to describe methods OnNext and OnGetDetailLine, and for more complex reports you can use methods OnGetGroupIndex, OnChangeIndex  and OnGetSumLine.

If you want to learn more about these subjects, see examples of reports in the Demo program.


Print Method

htmlReport Print cycle

function ThtmlReport.Execute: boolean;

begin

  Execute := False;

  BeginOfReport := True;

  EndOfReport := not NEXT;

  NewDetailLine := True;

  BeginOfReport := False;

  GetDetailHead( LINES);

  GetNewPageLine( LINES);

  PrintLines( LINES);

  Repeat

    I := Pred( ReportEndLevelCnt);

    While I >= FirstSumLevel do

    begin

      if EndOfReport or ( OldIdx[ I] <> GetGroupIndex( I)) then

      begin

        For J := FirstSumLevel to I do

        begin

          GetSumLine( J, LINES);

          ChangeIndex( J);

        end;

        if not EndOfReport then PutOldIdx( I);

        PrintLines( LINES);

        NewDetailLine := True;

        I := 0;

      end;

      Dec( I);

    end;

    if not EndOfReport then

    begin

      if NewDetailLine then

      begin

        DetailHeadSum;

        GetDetailHead( LINES);

      end;

      DetailSum;

      GetDetailLine( LINES);

      PrintLines( LINES);

      EndOfReport := not Next;

      if EndOfReport then LinesCnt := 0;

      NewDetailLine := False;

    end

    else Quit := True;

  until Quit;

  GetSumLine( EndOfReportLevel, LINES);

  PrintLines( LINES);

  Execute := True;

end;


Methods
htmlReport and Viewer Methods

       Execute

       BeginOfReport

       FieldByName

       FieldByNumber

       GetOldIdx

       GetPgNumber

       SetPrint

       Print

       Find

       LoadFromFile

       LoadFirst

       LoadLast

       LoadNext

       LoadPrior

       Show

       CopyToClipboard

         Clear


Execute
Execute Method

Declaration

function Execute: boolean;

Description

The Execute method performs  the main htmlReport  cycle  and returns True when it is accomplished correctly.


Clear
Clear Method

Declaration

procedure Clear;

Description

The Clear method clears the current document from the view window and deallocates the memory used.


Show
Show Method

Declaration

procedure Show;

Description

The Show method makes a htmlReport viewer form  visible by setting its Visible property to True.


LoadFromFile
LoadFromFile Method

Declaration

procedure LoadFromFile(const Filename: String);

Description

The LoadFromFile method loads an HTML document for viewing, where Filename is the name of the file to be loaded.  If Filename has no extension, .HTM is assumed.

Filename may optionally contain a document position identifier separated from the actual filename by a # sign.

Example

   Viewer.LoadFromFile('MyHTML#Contents');

would load MyHTML.htm and position the view to the location where the "Contents" target was defined.


LoadLast
LoadLast Method

Declaration

function LoadLast(const S: String; MatchCase: boolean): boolean;

Description

If the MultiLevel  propery is True, then the LoadLast method loads an HTML document for viewing that contains the highest level data. After this Find method is called.


GetOldIdx
GetOldIdx Method

Declaration

function GetOldIdx( Level: TReportLevel): String;

Description

The GetOldIdx method retrieves previous detail line index and returns it as string.

Usually you only need to use GetOldIdx  when working with sum lines wanted to specify the   detail lines group this sum is related to.


SetPrint
 SetPrint Method

Declaration

procedure SetPrint( Level: TReportLevel; FON: Boolean);

Description

The SetPrint method sets the htmlReport component's level visible property to the values passed in the FON parameter. The level visible property determines if the print method should print this level's data.


GetPgNumber
GetPgNumber Method

Declaration

function GetPgNumber: String;

Description

The GetPgNumber method returns the number of the current page.  Usually you only need to use GetPgNumber when working with page head then OnNewPageLine event occurs.


LoadNext
LoadNext Method

Declaration

function LoadNext(const S: String; MatchCase: boolean): boolean;

Description

If the MultiLevel  propery is True, then the LoadNext method loads an HTML document for viewing that contains data of the next  level. After this the Find method is called.


LoadPrior
LoadPrior Method

Declaration

function LoadPrior(const S: String; MatchCase: boolean): boolean;

Description

If the MultiLevel  propery is True, then the LoadPrior method loads an HTML document for viewing that contains data of the previous level. After this the Find method is called.


LoadFirst
LoadFirst Method

Declaration

function LoadFirst(const S: String; MatchCase: boolean): boolean;

Description

If the MultiLevel property is True, then the LoadFirst method loads an HTML document for viewing that contain the entire report. After this the Find method is called.


Find
Find Method

Declaration

function Find(const S: String; MatchCase: boolean): boolean;

Description

The Find method searches through the HTML document for the string, S, returning True if the string is found.  If MatchCase is True, a case sensitive search is made.

Text is searched starting at the current cursor position.  As each match is found, the cursor is placed at the end of the matched string.


Print
Print Method

Declaration

procedure Print(FromPage, ToPage: integer);

Description

Print prints the current document starting with FromPage and ending with ToPage.  Pages start at page 1.

Example

   Viewer.Print(1, 9999);

will print the entire document.


CopyToClipboard
CopyToClipboard Method

Declaration

procedure CopyToClipboard;

Description

The CopyToClipboard method copies the selected text to the clipboard.


BeginOfReport

Declaration

function BeginOfReport: Boolean;

Description

BeginOfReport is a Boolean function that indicates whether a report at its first abstract detail line. As you can see from the printing cycle this function returns "True" only once before the first  next  method.


FieldByNumber

You can access the value of a field with the FieldByNumber function of a htmlReport component, using as a parameter the ordinal number of the column in the report level (starting at 1). To access or change the field's value, convert the result with the appropriate conversion function, such as AsString or AsURL.

The FieldByNumber function of  htmlReport  enables you to specify a field  when you know the order of the fields in a report level, but not the name of the field. Use the FieldByNumber function to access data if  your application works with reports that don't have field names.

You can assign a value to a column in a report by assigning the appropriate FieldByNumber property to the value of a field. For example:

Report1.FieldByNumber(  TDetail, 1).AsString := '17/96';


FieldByName

The FieldByName function of  htmlReport enables you to point to a field  when you know the name of a fields in a report, but not its position in a report. To access the value of a field with FieldByName, specify the report component name, and then pass FieldByName the name of the column you want to access. To access or change the field's value, convert the result with the appropriate conversion function, such as AsString or AsURL.

For example, the following statement assigns the value of the Country column in the Customer table to Edit3:

Edit3.Text := Report1.FieldByName('INVOICE_NO').AsString;

You can assign a value to a column of a report by assigning the appropriate FieldByName property to the value of a component. For example:

Report1.FieldByName('INVOICE_NO').AsString := '17/96';


Format File Description
Structure

Html Report is divided into six sections:

                          report head

                          page head

                          detail lines head

                          detail lines

                          sum lines

                          end of report

Report head is printed only once on the first page. This section may be empty. Page head is printed on the first page and when the lines counter  reaches or exceed the limit determined by the page size property value.

Detail lines head is printed after sum lines when group index is changed. Sum lines are printed when report groups index are changed.

The definition of HtmlReport is a special form HTML file. All report sections can be placed in the format file. You can use htmlReport component editor to construct report format file. The

following information is necessary in case you are using HTML or text editor to create more complex reports.

Format file description:

These are the special characters used to create report format:

  Character        Meaning in format file

     ^              If a ^ character appears in the first column, the text that follows is a

                     format name ( format starts from the second line)

     ^              If a ^ character appears anywhere except for the first report format column,

                     it means decimal point place.

     @             If a @ character appears in the first column, the numbers that follow signify the

                     format level ( available values 0..15)

                                 0      -  report heading

                                 1      -  page heading

                                 2      -  detail lines heading

                                 3      -  detail lines

                               4..14  -  sum lines

                                15     -  end of report lines

      ?             The ? character shows the place of a report field in this position. Number of

                     contiguous ? describes field width.


TReportLevel
TReportLevel = ( tHead, tNewPage, tDetailHead, tDetail, tSum01,

                  tSum02, tSum03, tSum04, tSum05, tSum06,

                  tSum07, tSum08, tSum09, tSum10, tSum11, tEnd);


htmlReport Properties

Properties

                              Indicates a key or important property.

                      	            Indicates a run-time property.

      FormatFile

             FormatName

             MultiLevel

             PgSize

             PrnFile

Viewer Properties

  BorderStyle                             [image]     DefPreFontName

  CurrentFile                              [image]     ImageCacheCount

     DefBackground                        [image]     PopupMenu

     DefFontColor                           [image]     ViewImages

     DefFontName                           [image]     PopupMenu

     DefFontSize                                         WWidth,  WHeight

     DefHotSpotColor                                 WCaption


Events

    OnGetHeadLine

    OnGetNewPgLine

    OnChangeIndex

    OnDetailHeadSum

    OnDetailSum

    OnGetDetailHeadLine

    OnGetDetailLine

    OnGetGroupIndex

    OnGetSumLine

    OnNext

    OnProcessing

    OnVHotSpotClick


EventTypes
TNextEvent          = procedure( var PNext: Boolean)

TGetGroupIndexEvent = procedure( Level:   TReportLevel;

                                 var PIDX: String);

TGetSumLineEvent    = procedure( Level: TReportLevel);

TChangeIndexEvent   = procedure( Level: TReportLevel);

TProcessingEvent    = procedure( var PContinue: Boolean);


OnVHotSpotClick
OnVHotSpotClick Event

Declaration

property OnVHotSpotClick: THotSpotClickEvent;

Description

The OnHotSpotClick event occurs when the mouse is over an hypertext link and the left mouse button is clicked.


OnProcessing
OnProcessing Event

Declaration

property OnProcessing: TProcessingEvent;

Description

The OnProcessing event occurs whenever the viewer either begins or finishes an operation.  This event may be used to disable menuitems and/or buttons during time consuming operations.


OnGetHeadLine

Declaration

property OnGetHeadLine: TOnGetHeadLineEvent;

Description

The OnGetHeadLine event occurs when the htmlReport's object is needed data for the report heading lines printing. Use the OnGetHeadLine event handler when you want special processing to occur when this control ceases to be. You can find more information about htmlReport structure in the structures section


OnNext

Declaration

procedure OnNext( Sender: TObject; var PNext: Boolean);

Description

OnNext is activated when the htmlReport object moves cursor  forward by one abstract records.

This method has the only one specified characteristic:  when the printed data is over next has to give back the value "False", otherwise - "True".


OnChangeIndex

Declaration

property OnChangeIndex: TOnChangeIndexEvent;

Description

OnChangeIndex is activated when the value of the index field are changed.

You can take any special actions required by the event by assigning a method to this property.


OnDetailHeadSum

Declaration

property OnDetailHeadSum: TOnDetailHeadSumEvent;

Description

The OnDetailHeadSum event occurs when the htmlReport's object is ready for printing first line of the new detail lines group. As  you can see from the printing cycle this event occurs only once when group index changed.


OnDetailSum

Declaration

property OnDetailSum: TOnDetailSumEvent;

Description

The OnDetailSum event occurs when the htmlReport's object is ready for summing detail line fields. As you can see from the printing cycle this event occurs only once after each method next.


OnGetDetailHead
OnGetDetailHeadLine

Declaration

property OnGetDetailHeadLine: TOnGetDetailHeadEvent;

Description

The OnGetDetailHead event occurs when the htmlReport's object is ready for printing first line of the new detail lines group. Use the OnGetDetailHead event handler when you want to print detail lines group header. You can find more information about htmlReport structure in the structures section


OnGetDetailLine

Declaration

property OnGetDetailLine: TOnGetDetailLineEvent;

Description

The OnGetDetailLine event occurs when the htmlReport's object is ready to print detail line. As in any other report level,  you can put data for printing in two ways:

•	according to the name of report field:    FieldByName('FieldName').AsString

•	according to the number of report field: FieldByNumber( Number).AsString

Use the OnGetDetailLine event handler when you want to print after each OnNext method.

You can find more information about htmlReport structure in the structures section.


OnGetGroupIndex

Declaration

property OnGetGroupIndex: TOnGetGroupIndex;

Description

By moving from one detail line to another, htmlReport must know are there any changes at the data indices. For that purpose  the OnGetGroupIndex method  with the parameter of the sums level value is used. If  you want to print sum lines using this method,  you have to specify the values of the corresponding level data index.

You can find more information about htmlReport structure in the structures section.


OnGetNewPgLine

Declaration

property OnGetNewPgLine: TOnGetNewPgLineEvent;

Description

The OnGetNewPgLine event occurs when the htmlReport's object creates first report page or when the lines counter is equal or exceeds page size property value. Use the OnGetNewPgLine event handler when you want to put page number or some special information on each report page. You can find more information about htmlReport structure in the structures section.


OnGetSumLine

Declaration

property OnGetSumLine: TOnGetSumLine;

Description

The OnGetSumLine event occurs when the htmlReport's object is ready for printing report group summary lines or when the report is over. Use the OnGetSumLine event handler when you want to place summary fields or some special information after each detail lines group. You can find more information about htmlReport structure in the structures section


PopupMenu
PopupMenu Property

Declaration

property PopupMenu: TPopupMenu;

Description

The PopupMenu property identifies the name of the pop-up menu that appears when the user selects the htmlReport viewer window and presses the right mouse button (if the pop-up menu's AutoPopup property is True), or when the Popup method of the pop-up menu executes.


WWidth
WWidth Property

Declaration

property WWidth: Integer;

Description

The WWidth property determines the horizontal size of the viewer window in pixels. When you increase the WWidth property value, the viewer window becomes wider. If you decrease the value, the window becomes narrower.


WHeight
WHeight Property

Declaration

property WHeight: Integer;

Description

The WHeight property determines the vertical size of the viewer window in pixels.


WCaption
WCaption Property

Declaration

property WCaption: string;

Description

The Caption property is the text that appears in the htmlReport viewer's title bar; this text also appears as the icon label when the window is minimised.


BorderStyle Property

Declaration

property BorderStyle: TBorderStyle;

The BorderStyle property works slightly different from that for most Delphi components.  If the BorderStyle is set equal to bsSingle, the ThtmlViewer control will always have a single border.

However, if the BorderStyle is set equal to bsNone, the border will be removed when the control does not have the focus but will show when the control has the focus.


CurrentFile Property

Declaration

property CurrentFile: String;

Read only and run time only.  The CurrentFile property returns the full path and filename of the file currently loaded.  If no file is loaded or the load was accomplished using the LoadFromBuffer  method, CurrentFile will be an empty string.


DefBackground
DefBackground Property

Declaration

property DefBackground: TColor;

Description

DefBackground sets the viewer's default background color.  This is the background color when no background information is present in the HTML document file.  Either clBtnFace or clWindow are appropriate values.


DefFontColor
DefFontColor Property

Declaration

property DefFontColor: TColor;

Description

DefFontColor sets the viewer's default text color.  This is the color used when no text attribute information is present in the HTML document file.


DefFontName
DefFontName Property

Declaration

property DefFontName String;

Description

DefFontName sets the viewer's font name.


DefFontSize
DefFontSize Property

Declaration

property DefFontSize: Integer;

Description

DefFontSize sets the default font size for the viewer's normal text.  The value entered is the point size.  Headings, spacing, and other various sizes are scaled appropriately.


DefHotSpotColor
DefHotSpotColor Property

Declaration

property DefHotSpotColor: TColor;

Description

DefHotSpotColor sets the viewer's default color for links.  This is the color used if the link color is not otherwise specified in the HTML document file.


DefPreFontName
DefPreFontName Property

Declaration

property DefPreFontName String;

Description

DefPreFontName sets the viewer's font name for fonts used with the <pre>, <code>, and similar tags.  Normally a non-proportional font should be selected.


ImageCacheCount  Property

Declaration

property ImageCacheCount: Integer;

To save time in reloading HTML files with images, image caching may be used to save images already loaded.  The ImageCacheCount property determines the extent to which this is done.

With an ImageCacheCount of 5, for instance, images will be saved through 5 document reloads.  If the image is not used during that period, it will be dropped from the cache.  However, anytime an image is used, the count is reset to zero and it will remain for 5 more reloads.

The default value for ImageCacheCount is 5.  A value of 0 indicates no caching.  The cache may be flushed by setting the count to 0 temporarily and then resetting it to the desired value.

Since image storage can use a lot of memory, care should be taken not to overdo the amount of caching.


ViewImages Property

Declaration

property ViewImages: Boolean

Description

The ViewImages property determines whether inline images are drawn or simulated with a standard marker image.

If ViewImages is True and an image error occurs, an error image [image]  is displayed


PrnFile

Declaration

property PrnFile: String;

Description

The PrnFile property specifies the htmlReport output file to be saved by the Execute method.


PgSize

Declaration

property PgSize: Integer;

Description

The value of the PgSize property determines the number of lines in the report page. The default value is 64.


MultiLevel

Declaration

property MultiLevel: Boolean;

Description

The MultiLevel property determines if the print method should save each level in the separate HTML file. If MultiLevel is False, entire report is saved in the PrnFile. If the MultiLevel property  is True,  you can use LoadLast, LoadNext  and LoadPrior to skip between report levels.

The default value is False.


FormatName

Declaration

property FormatName: String;

Description

The FormatName property specifies the report in the format file to which the report is linked.

Changing the FormatFile value automatically sets the FormatName property.


 FormatFile

Declaration

property FormatFile: TFileName;

Description

The FormatFile property specifies the HTML format file to be used by Execute method.  At design time, you can use a file open dialog box to specify FormatFile property by clicking (…) in the Object inspector.  The FormatFile property can be set to the name of file that doesn't exist.

See Also

         Format File Structure


Main Report cycle
Main Report Loop

function THTMLReport.Execute: boolean;

begin

  Execute := False;

  FBeginOfReport := True;

  if not PutPrintFromTo then Exit;

  if Assigned( FOnNext) then

  begin

     PNext := False;

     FOnNext( Self, PNext);

     EndOfReport := not PNext;

  end

  else EndOfReport := True;

  PutOldIdx( Pred( LevelCnt));

  PrintOnOff;

  NewDetalLine := True;

  FBeginOfReport := False;

  Eil := EilPList.Create;

  if PrintLvl[ 0] then MakeLine( 0, Eil);

  if PrintLvl[ 1] then MakeLine( 1, Eil);

  For II := Pred( FirstLevel) to Pred( LevelCnt) do  if Assigned( PrintFile[ II]) then PrintLine( Eil, II);

  Eil.Destroy;

  Repeat

    I := LevelCnt - 1;

    While I >= FirstLevel do

    begin

      if EndOfReport or ( OldIdx^[ I] <> GetIdx( I)) then

      begin

        PrintOnOff;

        Eil := EilPList.Create;

        For J := FirstLevel to I do

        begin

          if PrintLvl[ J] then MakeLine( J, Eil);

          ClrSum( J);

        end;

        if not EndOfReport then PutOldIdx( I);

        For II := Pred( FirstLevel) to Pred( LevelCnt) do  if Assigned( PrintFile[ II]) then PrintLine( Eil, II);

        Eil.Destroy;

        NewDetalLine := True;

        I := 0;

      end;

      Dec( I);

    end;

    if not EndOfReport then

    begin

      PrintOnOff;

      Eil := EilPList.Create;

      if NewDetalLine then

      begin

        DetailHeadSum;

        if PrintLvl[ FirstLevel - 2] then MakeLine( FirstLevel - 2, Eil);

      end;

      DetailLineSum;

      if PrintLvl[ FirstLevel - 1] then MakeLine( FirstLevel - 1, Eil);

      For II := Pred( FirstLevel) to Pred( LevelCnt) do if Assigned( PrintFile[ II]) then PrintLine( Eil, II);

      Eil.Destroy;

      FOnNext( Self, PNext);

      EndOfReport := not PNext;

      if EndOfReport then For II := Pred( FirstLevel) to Pred( LevelCnt) do LnCnt[ II] := 0;

      NewDetalLine := False;

    end

    else Quit := True;

  until Quit;

  Eil := EilPList.Create;

  if PrintLvl[ LevelCnt] then MakeLine( LevelCnt, Eil);

  For II := Pred( FirstLevel) to Pred( LevelCnt) do if Assigned( PrintFile[ II]) then PrintLine( Eil, II);

  Eil.Destroy;

  Execute := True;

end;